package com.easy.controller;

import com.easy.bean.Carousel;
import com.easy.service.CarouselService;
import com.easy.util.ImageUtil;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

@RestController
@RequestMapping("/carousel")
@CrossOrigin
public class CarouselController {

    @Autowired
    private CarouselService carouselService;

    /**
     * 获取所有轮播图
     */
    @GetMapping("/list")
    public Result list() {
        List<Carousel> carouselList = carouselService.getAll();
        return Result.success(carouselList);
    }

    /**
     * 添加轮播图
     */
    @PostMapping
    public Result add(@RequestBody Carousel carousel) {
        Carousel result = carouselService.add(carousel);
        return Result.success("添加成功", result);
    }

    /**
     * 删除轮播图
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        int result = carouselService.delete(id);
        if (result > 0) {
            return Result.success("删除成功");
        } else {
            return Result.fail( 500,"删除失败");
        }
    }
}
